months = ['jan';'feb';'mar';'apr';'may';'jun';'jul';'aug';'sep';'oct';'nov';'dec'];
%years = ['00';'01';'02';'03';'04'];
years = ['00';'01';'02'];

in_path = 'c:\manoj\geomag\wdc\GeoMag_KKL\H0004\';
en = 0;
for i = 1:length(years),
    for j = 1:12,
        fid = fopen([in_path months(j,:) years(i,:)],'rt');
        days_in_month = daysinmonth(1999+i,j);
        st = en + 1;
        en = st + days_in_month-1;
        if fid == -1,
            data(st:en,1:24) = NaN;
            data1(st:en,1:24) = NaN;
            fprintf('File %s not avialable\n',[in_path months(j,:) years(i,:)]);
        else,
            for ii = 1:8,
                s = fgetl(fid);
            end;
            fprintf('%s\n',s);
            for ii = 1:3,
                s = fgetl(fid);
            end;
            for ii = 1:days_in_month,
                s = fgetl(fid);
                 if isempty(s) == 1 | length(s) < 10,
                    s = fgetl(fid);
                 else,
                data(st-1+ii,1:24)=sscanf(s(10:end),'%d',24);
                data1(st-1+ii,1:24) = data(st-1+ii,1:24) - nanmean(data(st-1+ii,19:21));
                 end;
               
            end;
            fclose(fid);
         end;
    end;
end;

L = (data1) == 0;
data1(L) = NaN;
L = abs(data1) > 200;
data1(L) = NaN;

L = (data) == 0;
data(L) = NaN;
L = abs(data) > 700;
data(L) = NaN;
data = data + 39000;

OBSdH(18,:,:) = data1(1:1096,:);
